﻿
@using IOA.MES.DataAccess.Enum
@{
    ViewBag.Title = "漏扫记录";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
    var workshops = ViewBag.Workshops as List<IOA.MES.DataAccess.VModel.VWorkshop>;
    var startTime = DateTime.Now.TimeOfDay < new TimeSpan(8, 0, 0) ? DateTime.Today.AddDays(-1).AddHours(20) : (DateTime.Now.TimeOfDay < new TimeSpan(20, 0, 0) ? DateTime.Today.AddHours(8) : DateTime.Today.AddHours(20));
    var endTime = DateTime.Now.TimeOfDay < new TimeSpan(8, 0, 0) ? DateTime.Today.AddHours(8) : (DateTime.Now.TimeOfDay < new TimeSpan(20, 0, 0) ? DateTime.Today.AddHours(20) : DateTime.Today.AddDays(1).AddHours(8));
}
@section Contents{
    <style>
        .layui-form-label {
            width: auto;
        }
    </style>
}

<div id="page"></div>

<script type="text/template" id="tplPage">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.WorkShop">车间：</label>
                        <div class="layui-input-inline">
                            <select id="selWorkshops1" lay-filter="selWorkshops">
                                @foreach (var item in workshops)
                                {
                                    <option value="@item.WorkshopCode" @(workshops.IndexOf(item) == 0 ? " selected " : "")>@item.WorkshopName</option>
                                }
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.ProduceTime">生产时间：</label>
                        <div class="layui-input-inline" style="width:440px;">
                            <input type="text" id="txtRangeTime" style="width:310px;float:left;" value="@(startTime.ToString("yyyy-MM-dd HH:mm:ss") + " 至 " + endTime.ToString("yyyy-MM-dd HH:mm:ss"))" autocomplete="off" class="layui-input">
                            <button class="layui-btn layuiadmin-btn-list layui-bg-cyan btnPreDuty" type="button" style="margin-top:-6px;">
                                <i class="layui-icon layui-icon-prev layuiadmin-button-btn"></i>
                            </button>
                            <button class="layui-btn layuiadmin-btn-list layui-bg-cyan btnNextDuty" type="button" style="margin-top:-6px;margin-left:0;">
                                <i class="layui-icon layui-icon-next layuiadmin-button-btn"></i>
                            </button>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button id="btnSearch1" class="layui-btn layuiadmin-btn-list" style="margin-top:-6px;" type="button">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                        <a id="btnDownload" class="layui-btn layuiadmin-btn-list" target="_blank" style="margin-top:-6px;" href="javascript:void(0)">
                            <i class="layui-icon layui-icon-download-circle layuiadmin-button-btn"></i>
                        </a>
                    </div>
                </div>
            </div>
            <div class="layui-card-body" id="chart1" style="height:500px;"></div>
        </div>
    </div>
</script>

@section Scripts{
    <script src="/res/echarts/echarts.min.js"></script>
    <script src="/res/echarts/macarons.js"></script>
    <script>
        var vm = new Vue({
            el: "#page",
            template: "#tplPage",
            data: {
                lang: JSON.parse(lang).package
            }
        });
        var option1 = {
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'shadow'
                }
            },
            legend: {
                data: ['全线']
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: {
                type: 'category',
                data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    name: '全线',
                    type: 'bar',
                    stack: '总量',
                    label: {
                        show: true,
                        position: 'inside'
                    },
                    data: [320, 302, 301, 334, 390, 330, 320]
                }
            ]
        };
        var myChart1 = echarts.init(document.getElementById('chart1'), 'macarons');
        setTimeout(function () {
            initLayui();
        }, 50);

        function initLayui() {
            layui.use(['table', 'layer', 'form', 'laydate', 'element'], function () {
                var layer = layui.layer,
                    table = layui.table,
                    form = layui.form,
                    laydate = layui.laydate;
                setTimeout(function () {
                    laydate.render({
                        elem: '.rangetime'
                        , type: 'datetime'
                        , rigger: 'click'
                        , range: '至'
                    });
                }, 100);

                $("#btnSearch1").click(function () {
                    queryCapacity();
                });
                queryCapacity();
                function queryCapacity() {
                    var workShopCode = $("#selWorkshops1").val(),
                        rangeTime = $("#txtRangeTime").val();
                    var startTime = rangeTime.split('至')[0].trim(),
                        endTime = rangeTime.split('至')[1].trim();

                    var loadId = layui.layer.load();
                    $.ajax({
                        url: "/Report/QueryMissingViaSiteComponents",
                        data: {
                            workShopCode: workShopCode,
                            startTime: startTime,
                            endTime: endTime
                        },
                        complete: function () {
                            layui.layer.close(loadId);
                        },
                        success: function (res) {
                            if (res.ErrCode != 200) {
                                layui.layer.msg(res.ErrMsg, { icon: 5 });
                                return;
                            }
                            option1.xAxis.data = res.Data.SiteTypes;
                            var series = new Array();
                            series.push({
                                name: "全线",
                                type: 'bar',
                                stack: '总量',
                                label: {
                                    show: true,
                                    position: 'inside'
                                },
                                data: []
                            });
                            for (var i = 0; i < res.Data.Report.length; i++) {
                                series[0].data.push(res.Data.Report[i].Value);
                            }
                            option1.series = series;
                            myChart1.setOption(option1);
                        }
                    });
                }

                $(document).on("click", "#btnDownload", function () {
                    var workShopCode = $("#selWorkshops1").val(),
                        rangeTime = $("#txtRangeTime").val();
                    var startTime = rangeTime.split('至')[0].trim(),
                        endTime = rangeTime.split('至')[1].trim();
                    $(this).attr("href", "/Report/ExportMissingViaSiteComponents?workshopCode=" + workShopCode + "&startTime=" + startTime + "&endTime=" + endTime);
                });
            });
        }
    </script>
}
